package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.LabProjectInstrument;
import com.ruoyi.system.service.ILabProjectInstrumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目创建实验仪器Controller
 *
 * @author jun.wang
 * @date 2022-04-12
 */
@RestController
@RequestMapping("/labbase/instrument")
public class LabProjectInstrumentController extends BaseController {
    @Autowired
    private ILabProjectInstrumentService labProjectInstrumentService;

    /**
     * 查询项目创建实验仪器列表
     */
    // @PreAuthorize("@ss.hasPermi('course:instrument:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabProjectInstrument labProjectInstrument) {
        startPage();
        List<LabProjectInstrument> list = labProjectInstrumentService.selectLabProjectInstrumentList(labProjectInstrument);
        return getDataTable(list);
    }

    /**
     * 导出项目创建实验仪器列表
     */
    // @PreAuthorize("@ss.hasPermi('course:instrument:export')")
    @Log(title = "项目创建实验仪器", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LabProjectInstrument labProjectInstrument) {
        List<LabProjectInstrument> list = labProjectInstrumentService.selectLabProjectInstrumentList(labProjectInstrument);
        ExcelUtil<LabProjectInstrument> util = new ExcelUtil<LabProjectInstrument>(LabProjectInstrument.class);
        return util.exportExcel(list, "instrument");
    }

    /**
     * 获取项目创建实验仪器详细信息
     */
    // @PreAuthorize("@ss.hasPermi('course:instrument:query')")
    @GetMapping(value = "/{instanceId}")
    public AjaxResult getInfo(@PathVariable("instanceId") Long instanceId) {
        return AjaxResult.success(labProjectInstrumentService.selectLabProjectInstrumentById(instanceId));
    }

    /**
     * 新增项目创建实验仪器
     */
    // @PreAuthorize("@ss.hasPermi('course:instrument:add')")
    @Log(title = "项目创建实验仪器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabProjectInstrument labProjectInstrument) {
        return toAjax(labProjectInstrumentService.insertLabProjectInstrument(labProjectInstrument));
    }

    /**
     * 修改项目创建实验仪器
     */
    // @PreAuthorize("@ss.hasPermi('course:instrument:edit')")
    @Log(title = "项目创建实验仪器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabProjectInstrument labProjectInstrument) {
        return toAjax(labProjectInstrumentService.updateLabProjectInstrument(labProjectInstrument));
    }

    /**
     * 删除项目创建实验仪器
     */
    // @PreAuthorize("@ss.hasPermi('course:instrument:remove')")
    @Log(title = "项目创建实验仪器", businessType = BusinessType.DELETE)
    @DeleteMapping("/{instanceIds}")
    public AjaxResult remove(@PathVariable Long[] instanceIds) {
        return toAjax(labProjectInstrumentService.deleteLabProjectInstrumentByIds(instanceIds));
    }
}
